package com.lxh.student.web.controller;


import com.lxh.student.common.Const;
import com.lxh.student.common.ResponseResult;
import com.lxh.student.entity.RcStudent;
import com.lxh.student.service.RcSystemService;
import com.lxh.student.util.TokenUtils;
import com.lxh.student.vo.input.LoginInputVo;
import com.lxh.student.vo.output.LoginInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController

public class SystemController {

    @Autowired
    private RcSystemService systemService;

//    @RequestMapping("/login")
//    public RcStudent doLogin(String username, String password, Integer type){
//        RcStudent rst =systemService.stuLogin(username, password, type);
//        return rst;
//    }


    @RequestMapping("/login")
    public ResponseResult doLogin(LoginInputVo inputVo, HttpSession session){
        ResponseResult responseResult = systemService.doLogin(inputVo);

        System.out.println("登录方法"+session.getId());
        //取出responseResult中的data数据，备用操作
        LoginInfoVo data = (LoginInfoVo) responseResult.getData();
        //保存数据到session
        session.setAttribute("is_login", data);
        //把登录的数据  responseResult里面的数据data先进行jwt编码，重新设置data数据
        String token = TokenUtils.getToken(data,Const.HOUR);
        //把编码加密好的data的数据(token令牌数据),替换掉responseResult中原来的明文data数据
        responseResult.setData(token);


        System.out.println("==============="+responseResult);
        return responseResult;
    }


}
